package cn.jk.config;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;
import org.springframework.stereotype.Component;


/**
 * spring的事件监听机制是同步执行的，如果当前有事务，事件也在事务中执行
 * 实现ResolvableTypeProvider接口，便可以增加事件泛型，可以解析事件泛型
 */
public class MyApplicationEvent<T> extends ApplicationEvent implements ResolvableTypeProvider {

	private static final long serialVersionUID = 1786692780107642622L;

	/**
	 * Create a new {@code ApplicationEvent}.
	 *
	 * @param source the object on which the event initially occurred or with
	 *               which the event is associated (never {@code null})
	 */
	public MyApplicationEvent(Object source) {
		super(source);
	}


	@Override
	public ResolvableType getResolvableType() {

		/**
		 * 返回该事件可解析的泛型类型
		 */
		return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(getSource()));
	}
}
